<?php

namespace App\Http\ViewComposers;

use App\Handlers\role;
use App\Models\Enum\Status;
use App\Services\Config\GamesService;
use Illuminate\View\View;
use App\Services\Config\ChannelsService;
use Illuminate\Support\Facades\Auth;

class GameRadioComposer
{

    public function __construct(GamesService $gamesService)
    {
        $this->gamesService = $gamesService;
    }

    public function compose(View $view)
    {
        $reqGameId = ($view->reqGameId == null ? old('game_id') : $view->reqGameId);
        $games = $this->gamesService->getGames(['status' => Status::NORMAL]);

        //拼出 渠道table
        $gameHtml = '';
        foreach ($games as $game) {
            $checked = '';

            if (isset($reqGameId) && $game['game_id'] == $reqGameId) {
                $checked = 'checked="checked"';
            }

            $gameHtml .= <<<EOF
<div class="col-sm-1" style="min-width: 20rem">
    <label>&emsp;{$game['game_name']}
            <input type="radio" class="pull-left" $checked name="game_id" value="{$game['game_id']}">
    </label>
</div>
EOF;
        }

        $view->with(compact('gameHtml'));
    }
}